{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Copyright (c) 2020, NVIDIA CORPORATION.\n",
    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "you may not use this file except in compliance with the License.\n",
    "You may obtain a copy of the License at\n",
    "    http://www.apache.org/licenses/LICENSE-2.0\n",
    "Unless required by applicable law or agreed to in writing, software\n",
    "distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "See the License for the specific language governing permissions and\n",
    "limitations under the License."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline  \n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import gc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DTYPES = {\n",
    "    '8': 'int32',\n",
    "    '10': 'int32',\n",
    "    '11': 'int32',\n",
    "    '13': 'int32',\n",
    "    '15': 'int32',\n",
    "    '16': 'int32',\n",
    "    '18': 'int32',\n",
    "    '20': 'float32',\n",
    "    '21': 'float32',\n",
    "    '22': 'float32',\n",
    "    '23': 'float32',\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15127684, 20)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dv = pd.read_csv('../input/val.tsv', sep='\\x01', header=None, dtype=DTYPES )\n",
    "gc.collect()\n",
    "dv.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>text_tokens</th>\n",
       "      <th>hashtags</th>\n",
       "      <th>tweet_id</th>\n",
       "      <th>media</th>\n",
       "      <th>links</th>\n",
       "      <th>domains</th>\n",
       "      <th>tweet_type</th>\n",
       "      <th>language</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>a_user_id</th>\n",
       "      <th>a_follower_count</th>\n",
       "      <th>a_following_count</th>\n",
       "      <th>a_is_verified</th>\n",
       "      <th>a_account_creation</th>\n",
       "      <th>b_user_id</th>\n",
       "      <th>b_follower_count</th>\n",
       "      <th>b_following_count</th>\n",
       "      <th>b_is_verified</th>\n",
       "      <th>b_account_creation</th>\n",
       "      <th>b_follows_a</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>101\\t47185\\t10157\\t100986\\t10343\\t55422\\t119\\t...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7647B4E9DAF4C1D8973397DC2A04F3E3</td>\n",
       "      <td>Photo</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>TopLevel</td>\n",
       "      <td>D3164C7FBCF2565DDF915B1B3AEFB1DC</td>\n",
       "      <td>1581703126</td>\n",
       "      <td>8A9AB92B775C62C4AB60DF6773A01571</td>\n",
       "      <td>13941</td>\n",
       "      <td>1216</td>\n",
       "      <td>False</td>\n",
       "      <td>1448292186</td>\n",
       "      <td>0000006C3074607050F1339DDCB890BB</td>\n",
       "      <td>27448</td>\n",
       "      <td>600</td>\n",
       "      <td>False</td>\n",
       "      <td>1520948869</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>101\\t6006\\t5086\\t1939\\t7418\\t3601\\t6406\\t1913\\...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>CCBFBA5AFE7EFC03102EA8D0F86C4208</td>\n",
       "      <td>Photo</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>TopLevel</td>\n",
       "      <td>22C448FF81263D4BAF2A176145EE9EAD</td>\n",
       "      <td>1581736431</td>\n",
       "      <td>187AC59639DA9A6F32F7CD118EDD58F7</td>\n",
       "      <td>476439</td>\n",
       "      <td>1478</td>\n",
       "      <td>False</td>\n",
       "      <td>1254447722</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>102</td>\n",
       "      <td>659</td>\n",
       "      <td>False</td>\n",
       "      <td>1478011810</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>101\\t56898\\t137\\t44851\\t10317\\t11490\\t10112\\t1...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>E18C2DCFC5AF20C650A0FD94598E69B7</td>\n",
       "      <td>Video</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Retweet</td>\n",
       "      <td>ECED8A16BE2A5E8871FD55F4842F16B1</td>\n",
       "      <td>1582061925</td>\n",
       "      <td>82626B53CB2AD3B469E4AE06EAA9D930</td>\n",
       "      <td>367</td>\n",
       "      <td>702</td>\n",
       "      <td>False</td>\n",
       "      <td>1518708926</td>\n",
       "      <td>00000860E80C67D8C46CE57C64DE9444</td>\n",
       "      <td>230</td>\n",
       "      <td>189</td>\n",
       "      <td>False</td>\n",
       "      <td>1541013180</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>101\\t13497\\t10437\\t94005\\t11161\\t73632\\t11067\\...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>26DC813FDF8546B757BB9141099F119E</td>\n",
       "      <td>NaN</td>\n",
       "      <td>D58137F9D688C88435FD64FBAEA82B97</td>\n",
       "      <td>E91CDEC8DC7ABF30592FA024616FF970</td>\n",
       "      <td>TopLevel</td>\n",
       "      <td>ECED8A16BE2A5E8871FD55F4842F16B1</td>\n",
       "      <td>1582110043</td>\n",
       "      <td>7AFE06FF54898A1E9C716F539831849E</td>\n",
       "      <td>278</td>\n",
       "      <td>1229</td>\n",
       "      <td>False</td>\n",
       "      <td>1243548061</td>\n",
       "      <td>00000865A1538142CDA5936B07FE4311</td>\n",
       "      <td>65</td>\n",
       "      <td>165</td>\n",
       "      <td>False</td>\n",
       "      <td>1452599043</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>101\\t24781\\t10152\\t42041\\t38268\\t10301\\t10798\\...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>30A33055566AAC9EB18734C4EAD11FE1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>AEF0CC9FA7B389B9A2ADF1331F00B65B</td>\n",
       "      <td>42DD9E2D4B2C0B0A71E909A6049EC2C2</td>\n",
       "      <td>TopLevel</td>\n",
       "      <td>D3164C7FBCF2565DDF915B1B3AEFB1DC</td>\n",
       "      <td>1581860270</td>\n",
       "      <td>D240DACE38CA84965270C86D47D3BF40</td>\n",
       "      <td>24313527</td>\n",
       "      <td>121</td>\n",
       "      <td>True</td>\n",
       "      <td>1177506290</td>\n",
       "      <td>00000865A1538142CDA5936B07FE4311</td>\n",
       "      <td>64</td>\n",
       "      <td>164</td>\n",
       "      <td>False</td>\n",
       "      <td>1452599043</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                         text_tokens hashtags  \\\n",
       "0  101\\t47185\\t10157\\t100986\\t10343\\t55422\\t119\\t...      NaN   \n",
       "1  101\\t6006\\t5086\\t1939\\t7418\\t3601\\t6406\\t1913\\...      NaN   \n",
       "2  101\\t56898\\t137\\t44851\\t10317\\t11490\\t10112\\t1...      NaN   \n",
       "3  101\\t13497\\t10437\\t94005\\t11161\\t73632\\t11067\\...      NaN   \n",
       "4  101\\t24781\\t10152\\t42041\\t38268\\t10301\\t10798\\...      NaN   \n",
       "\n",
       "                           tweet_id  media                             links  \\\n",
       "0  7647B4E9DAF4C1D8973397DC2A04F3E3  Photo                               NaN   \n",
       "1  CCBFBA5AFE7EFC03102EA8D0F86C4208  Photo                               NaN   \n",
       "2  E18C2DCFC5AF20C650A0FD94598E69B7  Video                               NaN   \n",
       "3  26DC813FDF8546B757BB9141099F119E    NaN  D58137F9D688C88435FD64FBAEA82B97   \n",
       "4  30A33055566AAC9EB18734C4EAD11FE1    NaN  AEF0CC9FA7B389B9A2ADF1331F00B65B   \n",
       "\n",
       "                            domains tweet_type  \\\n",
       "0                               NaN   TopLevel   \n",
       "1                               NaN   TopLevel   \n",
       "2                               NaN    Retweet   \n",
       "3  E91CDEC8DC7ABF30592FA024616FF970   TopLevel   \n",
       "4  42DD9E2D4B2C0B0A71E909A6049EC2C2   TopLevel   \n",
       "\n",
       "                           language   timestamp  \\\n",
       "0  D3164C7FBCF2565DDF915B1B3AEFB1DC  1581703126   \n",
       "1  22C448FF81263D4BAF2A176145EE9EAD  1581736431   \n",
       "2  ECED8A16BE2A5E8871FD55F4842F16B1  1582061925   \n",
       "3  ECED8A16BE2A5E8871FD55F4842F16B1  1582110043   \n",
       "4  D3164C7FBCF2565DDF915B1B3AEFB1DC  1581860270   \n",
       "\n",
       "                          a_user_id  a_follower_count  a_following_count  \\\n",
       "0  8A9AB92B775C62C4AB60DF6773A01571             13941               1216   \n",
       "1  187AC59639DA9A6F32F7CD118EDD58F7            476439               1478   \n",
       "2  82626B53CB2AD3B469E4AE06EAA9D930               367                702   \n",
       "3  7AFE06FF54898A1E9C716F539831849E               278               1229   \n",
       "4  D240DACE38CA84965270C86D47D3BF40          24313527                121   \n",
       "\n",
       "   a_is_verified  a_account_creation                         b_user_id  \\\n",
       "0          False          1448292186  0000006C3074607050F1339DDCB890BB   \n",
       "1          False          1254447722  00000776B07587ECA9717BFC301F2D6E   \n",
       "2          False          1518708926  00000860E80C67D8C46CE57C64DE9444   \n",
       "3          False          1243548061  00000865A1538142CDA5936B07FE4311   \n",
       "4           True          1177506290  00000865A1538142CDA5936B07FE4311   \n",
       "\n",
       "   b_follower_count  b_following_count  b_is_verified  b_account_creation  \\\n",
       "0             27448                600          False          1520948869   \n",
       "1               102                659          False          1478011810   \n",
       "2               230                189          False          1541013180   \n",
       "3                65                165          False          1452599043   \n",
       "4                64                164          False          1452599043   \n",
       "\n",
       "   b_follows_a  \n",
       "0         True  \n",
       "1        False  \n",
       "2         True  \n",
       "3         True  \n",
       "4        False  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features = [\n",
    "    'text_tokens',    ###############\n",
    "    'hashtags',       #Tweet Features\n",
    "    'tweet_id',       #\n",
    "    'media',          #\n",
    "    'links',          #\n",
    "    'domains',        #\n",
    "    'tweet_type',     #\n",
    "    'language',       #\n",
    "    'timestamp',      ###############\n",
    "    'a_user_id',              ###########################\n",
    "    'a_follower_count',       #Engaged With User Features\n",
    "    'a_following_count',      #\n",
    "    'a_is_verified',          #\n",
    "    'a_account_creation',     ###########################\n",
    "    'b_user_id',              #######################\n",
    "    'b_follower_count',       #Engaging User Features\n",
    "    'b_following_count',      #\n",
    "    'b_is_verified',          #\n",
    "    'b_account_creation',     #######################\n",
    "    'b_follows_a',    #################### Engagement Features\n",
    "    #'reply',          #Target Reply\n",
    "    #'retweet',        #Target Retweet    \n",
    "    #'retweet_comment',#Target Retweet with comment\n",
    "    #'like',           #Target Like\n",
    "                      ####################\n",
    "]\n",
    "dv.columns = features\n",
    "gc.collect()\n",
    "dv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>tweet_id</th>\n",
       "      <th>b_user_id</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7647B4E9DAF4C1D8973397DC2A04F3E3</td>\n",
       "      <td>0000006C3074607050F1339DDCB890BB</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CCBFBA5AFE7EFC03102EA8D0F86C4208</td>\n",
       "      <td>00000776B07587ECA9717BFC301F2D6E</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>E18C2DCFC5AF20C650A0FD94598E69B7</td>\n",
       "      <td>00000860E80C67D8C46CE57C64DE9444</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>26DC813FDF8546B757BB9141099F119E</td>\n",
       "      <td>00000865A1538142CDA5936B07FE4311</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>30A33055566AAC9EB18734C4EAD11FE1</td>\n",
       "      <td>00000865A1538142CDA5936B07FE4311</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           tweet_id                         b_user_id  \\\n",
       "0  7647B4E9DAF4C1D8973397DC2A04F3E3  0000006C3074607050F1339DDCB890BB   \n",
       "1  CCBFBA5AFE7EFC03102EA8D0F86C4208  00000776B07587ECA9717BFC301F2D6E   \n",
       "2  E18C2DCFC5AF20C650A0FD94598E69B7  00000860E80C67D8C46CE57C64DE9444   \n",
       "3  26DC813FDF8546B757BB9141099F119E  00000865A1538142CDA5936B07FE4311   \n",
       "4  30A33055566AAC9EB18734C4EAD11FE1  00000865A1538142CDA5936B07FE4311   \n",
       "\n",
       "   prediction  \n",
       "0           0  \n",
       "1           0  \n",
       "2           0  \n",
       "3           0  \n",
       "4           0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dv = dv[['tweet_id','b_user_id']].copy()\n",
    "dv['prediction'] = 0\n",
    "dv.to_csv( 'sample_submission_public.csv', index=False )\n",
    "dv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dv = pd.read_csv('../input/competition_test.tsv', sep='\\x01', header=None, dtype=DTYPES )\n",
    "dv.columns = features\n",
    "gc.collect()\n",
    "print( dv.shape )\n",
    "dv.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dv = dv[['tweet_id','b_user_id']].copy()\n",
    "dv['prediction'] = 0\n",
    "dv.to_csv( 'sample_submission_private.csv', index=False )\n",
    "dv.head()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
